package shujia.day15;
/*
    实现Runnable接口实现电影院售票
    某电影院目前正在上映贺岁大片，共有100张票，而它有3个售票窗口售票，请设计一个程序模拟该电影院售票。

 */
class MyRunnable2 implements Runnable{
    int tickets = 100;
    @Override
    public void run() {
        while (true){
            if(tickets>0){
                System.out.println(Thread.currentThread().getName()+" 正在出售第 "+(tickets--)+" 张票。。");
            }
        }
    }
}

public class SellTicketDemo2 {
    public static void main(String[] args) {
        MyRunnable2 myRunnable2 = new MyRunnable2();

        Thread w1 = new Thread(myRunnable2, "窗口1");
        Thread w2 = new Thread(myRunnable2, "窗口2");
        Thread w3 = new Thread(myRunnable2, "窗口3");

        w1.start();
        w2.start();
        w3.start();
    }
}
